package com.longcai.cm.base.config;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @author libingxing
 */
@Component
public class AutoFillMetaObjectHandler implements MetaObjectHandler {

    /**
     * @param metaObject 透传实体
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        // 创建时间，取当前时间，也可以自定义
        this.strictInsertFill(metaObject, "createTime", String.class, DateUtil.now());
    }

    /**
     * @param metaObject
     */
    @Override
    public void updateFill(MetaObject metaObject) {
//        创建时间，取当前时间，也可以自定义
        this.strictUpdateFill(metaObject, "createTime", String.class, DateUtil.now());
        this.strictUpdateFill(metaObject, "updateTime", String.class, DateUtil.now());
    }

}
